#!/bin/bash

# 设置任务和结果选项
task1="1、检测线EFC"
task2="2、商品化EFC"
task3="3、淋雨线EFC"
task4="4、路试EFC"
task5="5、EFC返修"
task6="6、退出"

result0="0、失败"
result1="1、成功"
result2="2、待定"
result3="3、暂停"
result4="4、继续"
result5="5、紧急停止"

main_menu() {
    clear
    echo "请选择任务："
    echo "$task1"
    echo "$task2"
    echo "$task3"
    echo "$task4"
    echo "$task5"
    echo "$task6"
    read -p "请输入任务编号（1-6）：" task_choice

    if [ "$task_choice" -eq 6 ]; then
        exit_script
    elif [ "$task_choice" -lt 1 ] || [ "$task_choice" -gt 5 ]; then
        main_menu
    else
        tag=$((task_choice - 1))
        choose_result
    fi
}

choose_result() {
    clear
    echo "请选择结果："
    echo "$result0"
    echo "$result1"
    echo "$result2"
    echo "$result3"
    echo "$result4"
    echo "$result5"
    read -p "请输入结果编号（0-5）：" result_choice

    if [ "$result_choice" -lt 0 ] || [ "$result_choice" -gt 5 ]; then
        choose_result
    elif [ "$result_choice" -eq 5 ]; then
        emergency_stop
    else
        adb shell am broadcast -a com.dfl.CAR_MACHINE_CALLBACK -n com.dfl.cartest/.sysSettings.utils.CarBroadcastReceiver --ei result $result_choice --ei tag $tag
        choose_result
    fi
}

emergency_stop() {
    clear
    echo "紧急停止："
    adb shell am broadcast -a com.dfl.CAR_MACHINE_CALLBACK -n com.dfl.cartest/.sysSettings.utils.CarBroadcastReceiver --ei result 5 --ei tag $tag
    sleep 2
    main_menu
}

exit_script() {
    clear
    echo "操作完成，程序退出！"
    sleep 2
    exit 0
}

# 启动脚本
main_menu
